package top.v5it.japi.ddd.tool;

import java.io.Serializable;

/**
 * @author zhanpu
 * @date 2023/4/12
 */
public class Column implements Serializable {

    private static final long serialVersionUID = 1681355551679L;

    private String columnName;
    private String columnType;

    public Column(String columnName, String columnType) {
        this.columnName = columnName;
        this.columnType = getColumnType(columnType);
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public String getColumnType() {
        return columnType;
    }

    public void setColumnType(String columnType) {
        this.columnType = columnType;
    }

    private String getColumnType(String columnType) {
        if (columnType.contains("VARCHAR") || columnType.contains("TEXT")) return "String";
        if (columnType.contains("BIT")) return "java.lang.Boolean";
        if (columnType.contains("TINYINT")) return "java.lang.Byte";
        if (columnType.contains("SMALLINT")) return "java.lang.Short";
        if (columnType.contains("INT")) return "java.lang.Integer";
        if (columnType.contains("BIGINT")) return "java.lang.Long";
        if (columnType.contains("FLOAT")) return "java.lang.Float";
        if (columnType.contains("DOUBLE")) return "java.lang.Double";
        if (columnType.contains("DECIMAL")) return "java.math.BigDecimal";
        if (columnType.contains("DATE") || columnType.contains("TIME") || columnType.contains("YEAR"))
            return "java.util.Date";
        if (columnType.contains("DATETIME") || columnType.contains("TIMESTAMP"))
            return "java.sql.Timestamp";
        else return "Object";
    }
}
